


/* 行政区域 - 省*/
export const dict_province = [
  { label: '广东省', value: '44' }
]
/* 行政区域 - 市*/
export const dict_city = [
  { label: '深圳市', value: '4403' }
]
/* 行政区域 - 区（深圳） */
export const dict_district = [
  { label: '罗湖区', value: '440303' },
  { label: '福田区', value: '440304' },
  { label: '南山区', value: '440305' },
  { label: '宝安区', value: '440306' },
  { label: '龙岗区', value: '440307' },
  { label: '盐田区', value: '440308' },
  { label: '龙华区', value: '440309' },
  { label: '坪山区', value: '440310' },
  { label: '光明区', value: '440311' },
  { label: '大鹏新区', value: '440312' }
]


/* 设备注册状态 */
export const DEVICE_REGISTER_STATUS_UNDO = 0
export const DEVICE_REGISTER_STATUS_COMPLETE = 1
export const dict_deviceRegisterStatus = [
  { label: '未注册', value: DEVICE_REGISTER_STATUS_UNDO },
  { label: '已注册', value: DEVICE_REGISTER_STATUS_COMPLETE }
]

/* 设备注册类型 */
export const DEVICE_REGISTER_TYPE_TERMINAL = 0
export const dict_deviceRegisterType = [
  { label: '终端注册', value: DEVICE_REGISTER_TYPE_TERMINAL },
]

/* 产品类型 */
export const PRODUCTION_TYPE_MEASURE_MODULE = 0
export const PRODUCTION_TYPE_TEST_DEVICE = 1

export const MEM_TYPE = 0
export const WOMEM_TYPE = 1
export const dict_productionType = [
  { label: '男', value: MEM_TYPE },
  { label: '女', value: WOMEM_TYPE },
]

export const USER_USE_STATUS = 0
export const USER_NO_USE_STATUS = 1
export const dict_userStatus = [
  { label: '正常', value: USER_USE_STATUS },
  { label: '禁用', value: USER_NO_USE_STATUS },
]

export const dict_goodsStatus= [
  { label: '使用中', value: 0 },
  { label: '已下架', value: 1 }
]

// export const MEM_TYPE = 0
// export const WOMEM_TYPE = 1
// export const dict_genderType = [
//   { label: '男', value: MEM_TYPE },
//   { label: '女', value: WOMEM_TYPE },
// ]

/* 设备状态 */
export const DEVICE_STATUS_OFFLINE = 0  /* 离线 */
export const DEVICE_STATUS_ONLINE = 1   /* 在线 */

/* 设备账号状态 */
export const DEVICE_ACCOUNT_STATUS_INACTIVE = 0   /* 禁用 */
export const DEVICE_ACCOUNT_STATUS_ACTIVE = 1     /* 启用 */
/* OTA状态 */
export const DEVICE_OTA_INACTIVE = 0  /* 未启用 */
export const DEVICE_OTA_ACTIVE = 1    /* 启用 */

/**
 * 从字典列表中，获取value对应的label
 * 
 * @author jeffrey
 * @param {Array} dictionary 字典列表，label，value
 * @param {*} value 属性值
 * @returns 返回dictionary中value对应的label
 * 
 */
export const transformDisplayName = (dictionary, value) => {
  if((value ?? '') !== '') {
    const target = dictionary.find(item => item.value == value)
  
    if(target) {
      return target.label
    } else {
      // console.warn( '未知值：' + value, '字典:', dictionary)
      return '未知'
    }
  } else {
    return '- -'
  }
}

/**
 * 获取行政区域的联级结构
 * 
 * @author jeffrey
 * @returns 返回符合ElCascader组件的数据格式
 * 
 */
export const getAreaCascader = () => {
  const list = []

  dict_province.forEach(province => {
    const _province = {
      label: province.label,
      value: province.value,
      children: []
    }

    const cityList = dict_city.filter(city => city.value.startsWith(province.value))

    cityList.forEach(city => {
      const _city = {
        label: city.label,
        value: city.value,
        children: dict_district.filter(district => district.value.startsWith(city.value))
      }
      _province.children.push(_city)
    })
    list.push(_province)

  })


  return list
}
